﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace IDE
{
    public partial class Parameter : Form
    {
        string maxlinea;
        string maxdigit;
        string maxid;
        string longfecha;
        public Parameter(){
            InitializeComponent();
            cargarParametros();
        }

        private void cargarParametros(){
            ArrayList lineas = new ArrayList();
           //StreamReader f = new StreamReader(new FileStream("parser\\param.txt", FileMode.Open));
            StreamReader f = new StreamReader(new FileStream("param.txt", FileMode.Open));

            String linea;
            while ((linea = f.ReadLine()) != null)
            {
                lineas.Add(linea);
                if (linea.Contains("MAXLINEA"))
                {
                    maxlinea = linea.Substring(9);
                    txtMaxLinea.Text = maxlinea;
                }
                else if (linea.Contains("MAXDIGIT"))
                {
                    maxdigit = linea.Substring(9);
                    txtMaxDigit.Text = maxdigit;
                }
                else if (linea.Contains("MAXID"))
                {
                    maxid = linea.Substring(6);
                    txtMaxId.Text = maxid;
                }
                else if (linea.Contains("LONG_FECHA"))
                {
                    longfecha = linea.Substring(11);
                    txtLongFecha.Text = longfecha;
                }
            }

            f.Close();
        }

        private void btnAccept_Click(object sender, EventArgs e){
            //using (StreamWriter f = new StreamWriter(new FileStream("parser\\param.txt", FileMode.Create)))
            using (StreamWriter f = new StreamWriter(new FileStream("param.txt", FileMode.Create)))
            {
                String param = "MAXLINEA;" + txtMaxLinea.Text + "\r\n" +
                               "MAXDIGIT;" + txtMaxDigit.Text + "\r\n" +
                               "MAXID;" + txtMaxId.Text + "\r\n"+
                               "LONG_FECHA;" + txtLongFecha.Text + "\r\n";
                f.Write(param);
                f.Close();
            }
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e){
            this.Dispose();
        }
    }
}
